<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module Fiddle::CParser - fiddle: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-compact">#compact</a>
    <li ><a href="#method-i-parse_ctype">#parse_ctype</a>
    <li ><a href="#method-i-parse_signature">#parse_signature</a>
    <li ><a href="#method-i-parse_struct_signature">#parse_struct_signature</a>
    <li ><a href="#method-i-split_arguments">#split_arguments</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-Fiddle::CParser">
    <h1 id="module-Fiddle::CParser" class="module">
      module Fiddle::CParser
    </h1>

    <section class="description">
    
<p>A mixin that provides methods for parsing C struct and prototype signatures.</p>

<h2 id="module-Fiddle::CParser-label-Example">Example<span><a href="#module-Fiddle::CParser-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;fiddle/import&#39;</span>

<span class="ruby-identifier">include</span> <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">CParser</span>
  <span class="ruby-comment">#=&gt; Object</span>

<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-string">&#39;int&#39;</span>)
  <span class="ruby-comment">#=&gt; Fiddle::TYPE_INT</span>

<span class="ruby-identifier">parse_struct_signature</span>([<span class="ruby-string">&#39;int i&#39;</span>, <span class="ruby-string">&#39;char c&#39;</span>])
  <span class="ruby-comment">#=&gt; [[Fiddle::TYPE_INT, Fiddle::TYPE_CHAR], [&quot;i&quot;, &quot;c&quot;]]</span>

<span class="ruby-identifier">parse_signature</span>(<span class="ruby-string">&#39;double sum(double, double)&#39;</span>)
  <span class="ruby-comment">#=&gt; [&quot;sum&quot;, Fiddle::TYPE_DOUBLE, [Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]]</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-parse_ctype" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse_ctype</span><span
                                class="method-args">(ty, tymap=nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Given a String of C type <code>ty</code>, returns the corresponding <a href="../Fiddle.html"><code>Fiddle</code></a> constant.</p>

<p><code>ty</code> can also accept an Array of C type Strings, and will be returned in a corresponding Array.</p>

<p>If Hash <code>tymap</code> is provided, <code>ty</code> is expected to be the key, and the value will be the C type to be looked up.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;fiddle/import&#39;</span>

<span class="ruby-identifier">include</span> <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">CParser</span>
  <span class="ruby-comment">#=&gt; Object</span>

<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-string">&#39;int&#39;</span>)
  <span class="ruby-comment">#=&gt; Fiddle::TYPE_INT</span>

<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-string">&#39;double diff&#39;</span>)
  <span class="ruby-comment">#=&gt; Fiddle::TYPE_DOUBLE</span>

<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-string">&#39;unsigned char byte&#39;</span>)
  <span class="ruby-comment">#=&gt; -Fiddle::TYPE_CHAR</span>

<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-string">&#39;const char* const argv[]&#39;</span>)
  <span class="ruby-comment">#=&gt; -Fiddle::TYPE_VOIDP</span>
</pre>

                              <div class="method-source-code" id="parse_ctype-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle/cparser.rb, line 149</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse_ctype</span>(<span class="ruby-identifier">ty</span>, <span class="ruby-identifier">tymap</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">tymap</span> <span class="ruby-operator">||=</span> {}
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">ty</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
    <span class="ruby-keyword">return</span> [<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">ty</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">tymap</span>), <span class="ruby-identifier">ty</span>[<span class="ruby-value">1</span>]]
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">ty</span> = <span class="ruby-identifier">ty</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/\Aconst\s+/</span>, <span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">ty</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&#39;void&#39;</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_VOID</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:(?:signed\s+)?long\s+long(?:\s+int\s+)?|int64_t)(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_LONG_LONG</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_LONG_LONG</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:unsigned\s+long\s+long(?:\s+int\s+)?|uint64_t)(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_LONG_LONG</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_ULONG_LONG</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aunsigned\s+long(?:\s+int\s+)?(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Aunsigned\s+int\s+long(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Along(?:\s+int)?\s+unsigned(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Aint\s+unsigned\s+long(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\A(?:int\s+)?long\s+unsigned(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_ULONG</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:signed\s+)?long(?:\s+int\s+)?(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\A(?:signed\s+)?int\s+long(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Along(?:\s+int)?\s+signed(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_LONG</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aunsigned\s+short(?:\s+int\s+)?(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Aunsigned\s+int\s+short(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Ashort(?:\s+int)?\s+unsigned(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Aint\s+unsigned\s+short(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\A(?:int\s+)?short\s+unsigned(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_USHORT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:signed\s+)?short(?:\s+int\s+)?(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\A(?:signed\s+)?int\s+short(?:\s+\w+)?\z/</span>,
       <span class="ruby-regexp">/\Aint\s+(?:signed\s+)?short(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_SHORT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:signed\s+)?int(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_INT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:unsigned\s+int|uint)(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_UINT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\A(?:signed\s+)?char(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_CHAR</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aunsigned\s+char(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span>  <span class="ruby-constant">TYPE_UCHAR</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aint8_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT8_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_INT8_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Auint8_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT8_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_UINT8_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aint16_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT16_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_INT16_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Auint16_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT16_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_UINT16_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aint32_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT32_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_INT32_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Auint32_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT32_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_UINT32_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aint64_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT64_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_INT64_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Auint64_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">unless</span> <span class="ruby-constant">Fiddle</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-value">:TYPE_INT64_T</span>)
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>, <span class="ruby-node">&quot;unsupported type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_UINT64_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Afloat(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_FLOAT</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Adouble(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_DOUBLE</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Asize_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_SIZE_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Assize_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_SSIZE_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aptrdiff_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_PTRDIFF_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Aintptr_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_INTPTR_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\Auintptr_t(?:\s+\w+)?\z/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_UINTPTR_T</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;bool&quot;</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_BOOL</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/\*/</span>, <span class="ruby-regexp">/\[[\s\d]*\]/</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_VOIDP</span>
  <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;...&quot;</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">TYPE_VARIADIC</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">ty</span> = <span class="ruby-identifier">ty</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39; &#39;</span>, <span class="ruby-value">2</span>)[<span class="ruby-value">0</span>]
    <span class="ruby-keyword">if</span>( <span class="ruby-identifier">tymap</span>[<span class="ruby-identifier">ty</span>] )
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">tymap</span>[<span class="ruby-identifier">ty</span>], <span class="ruby-identifier">tymap</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">DLError</span>, <span class="ruby-node">&quot;unknown type: #{ty}&quot;</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-parse_signature" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse_signature</span><span
                                class="method-args">(signature, tymap=nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Parses a C prototype signature</p>

<p>If Hash <code>tymap</code> is provided, the return value and the arguments from the <code>signature</code> are expected to be keys, and the value will be the C type to be looked up.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;fiddle/import&#39;</span>

<span class="ruby-identifier">include</span> <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">CParser</span>
  <span class="ruby-comment">#=&gt; Object</span>

<span class="ruby-identifier">parse_signature</span>(<span class="ruby-string">&#39;double sum(double, double)&#39;</span>)
  <span class="ruby-comment">#=&gt; [&quot;sum&quot;, Fiddle::TYPE_DOUBLE, [Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE]]</span>

<span class="ruby-identifier">parse_signature</span>(<span class="ruby-string">&#39;void update(void (*cb)(int code))&#39;</span>)
  <span class="ruby-comment">#=&gt; [&quot;update&quot;, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP]]</span>

<span class="ruby-identifier">parse_signature</span>(<span class="ruby-string">&#39;char (*getbuffer(void))[80]&#39;</span>)
  <span class="ruby-comment">#=&gt; [&quot;getbuffer&quot;, Fiddle::TYPE_VOIDP, []]</span>
</pre>

                              <div class="method-source-code" id="parse_signature-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle/cparser.rb, line 109</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse_signature</span>(<span class="ruby-identifier">signature</span>, <span class="ruby-identifier">tymap</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">tymap</span> <span class="ruby-operator">||=</span> {}
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">compact</span>(<span class="ruby-identifier">signature</span>)
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^(?:[\w\*\s]+)\(\*(\w+)\((.*?)\)\)(?:\[\w*\]|\(.*?\));?$/</span>
    <span class="ruby-identifier">func</span>, <span class="ruby-identifier">args</span> = <span class="ruby-node">$1</span>, <span class="ruby-node">$2</span>
    <span class="ruby-keyword">return</span> [<span class="ruby-identifier">func</span>, <span class="ruby-constant">TYPE_VOIDP</span>, <span class="ruby-identifier">split_arguments</span>(<span class="ruby-identifier">args</span>).<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span> <span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">arg</span>, <span class="ruby-identifier">tymap</span>)}]
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^([\w\*\s]+[\*\s])(\w+)\((.*?)\);?$/</span>
    <span class="ruby-identifier">ret</span>, <span class="ruby-identifier">func</span>, <span class="ruby-identifier">args</span> = <span class="ruby-node">$1</span>.<span class="ruby-identifier">strip</span>, <span class="ruby-node">$2</span>, <span class="ruby-node">$3</span>
    <span class="ruby-keyword">return</span> [<span class="ruby-identifier">func</span>, <span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">ret</span>, <span class="ruby-identifier">tymap</span>), <span class="ruby-identifier">split_arguments</span>(<span class="ruby-identifier">args</span>).<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span> <span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">arg</span>, <span class="ruby-identifier">tymap</span>)}]
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>,<span class="ruby-node">&quot;can&#39;t parse the function prototype: #{signature}&quot;</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-parse_struct_signature" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse_struct_signature</span><span
                                class="method-args">(signature, tymap=nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Parses a C struct’s members</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;fiddle/import&#39;</span>

<span class="ruby-identifier">include</span> <span class="ruby-constant">Fiddle</span><span class="ruby-operator">::</span><span class="ruby-constant">CParser</span>
  <span class="ruby-comment">#=&gt; Object</span>

<span class="ruby-identifier">parse_struct_signature</span>([<span class="ruby-string">&#39;int i&#39;</span>, <span class="ruby-string">&#39;char c&#39;</span>])
  <span class="ruby-comment">#=&gt; [[Fiddle::TYPE_INT, Fiddle::TYPE_CHAR], [&quot;i&quot;, &quot;c&quot;]]</span>

<span class="ruby-identifier">parse_struct_signature</span>([<span class="ruby-string">&#39;char buffer[80]&#39;</span>])
  <span class="ruby-comment">#=&gt; [[[Fiddle::TYPE_CHAR, 80]], [&quot;buffer&quot;]]</span>
</pre>

                              <div class="method-source-code" id="parse_struct_signature-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle/cparser.rb, line 35</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse_struct_signature</span>(<span class="ruby-identifier">signature</span>, <span class="ruby-identifier">tymap</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">signature</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
    <span class="ruby-identifier">signature</span> = <span class="ruby-identifier">split_arguments</span>(<span class="ruby-identifier">signature</span>, <span class="ruby-regexp">/[,;]/</span>)
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">signature</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
    <span class="ruby-identifier">signature</span> = [<span class="ruby-identifier">signature</span>]
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">mems</span> = []
  <span class="ruby-identifier">tys</span>  = []
  <span class="ruby-identifier">signature</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">msig</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">msig</span> = <span class="ruby-identifier">compact</span>(<span class="ruby-identifier">msig</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">msig</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">msig</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Hash</span>
      <span class="ruby-identifier">msig</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">struct_name</span>, <span class="ruby-identifier">struct_signature</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">struct_name</span> = <span class="ruby-identifier">struct_name</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">struct_name</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
        <span class="ruby-identifier">struct_name</span> = <span class="ruby-identifier">compact</span>(<span class="ruby-identifier">struct_name</span>)
        <span class="ruby-identifier">struct_count</span> = <span class="ruby-keyword">nil</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">struct_name</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/^([\w\*\s]+)\[(\d+)\]$/</span>
          <span class="ruby-identifier">struct_count</span> = <span class="ruby-node">$2</span>.<span class="ruby-identifier">to_i</span>
          <span class="ruby-identifier">struct_name</span> = <span class="ruby-node">$1</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">struct_signature</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:entity_class</span>)
          <span class="ruby-identifier">struct_type</span> = <span class="ruby-identifier">struct_signature</span>
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">parsed_struct</span> = <span class="ruby-identifier">parse_struct_signature</span>(<span class="ruby-identifier">struct_signature</span>, <span class="ruby-identifier">tymap</span>)
          <span class="ruby-identifier">struct_type</span> = <span class="ruby-constant">CStructBuilder</span>.<span class="ruby-identifier">create</span>(<span class="ruby-constant">CStruct</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">parsed_struct</span>)
        <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">if</span> <span class="ruby-identifier">struct_count</span>
          <span class="ruby-identifier">ty</span> = [<span class="ruby-identifier">struct_type</span>, <span class="ruby-identifier">struct_count</span>]
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">ty</span> = <span class="ruby-identifier">struct_type</span>
        <span class="ruby-keyword">end</span>
        <span class="ruby-identifier">mems</span>.<span class="ruby-identifier">push</span>([<span class="ruby-identifier">struct_name</span>, <span class="ruby-identifier">struct_type</span>.<span class="ruby-identifier">members</span>])
        <span class="ruby-identifier">tys</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">ty</span>)
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^[\w\*\s]+[\*\s](\w+)$/</span>
      <span class="ruby-identifier">mems</span>.<span class="ruby-identifier">push</span>(<span class="ruby-node">$1</span>)
      <span class="ruby-identifier">tys</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">msig</span>, <span class="ruby-identifier">tymap</span>))
    <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^[\w\*\s]+\(\*(\w+)\)\(.*?\)$/</span>
      <span class="ruby-identifier">mems</span>.<span class="ruby-identifier">push</span>(<span class="ruby-node">$1</span>)
      <span class="ruby-identifier">tys</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-identifier">msig</span>, <span class="ruby-identifier">tymap</span>))
    <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^([\w\*\s]+[\*\s])(\w+)\[(\d+)\]$/</span>
      <span class="ruby-identifier">mems</span>.<span class="ruby-identifier">push</span>(<span class="ruby-node">$2</span>)
      <span class="ruby-identifier">tys</span>.<span class="ruby-identifier">push</span>([<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-node">$1</span>.<span class="ruby-identifier">strip</span>, <span class="ruby-identifier">tymap</span>), <span class="ruby-node">$3</span>.<span class="ruby-identifier">to_i</span>])
    <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^([\w\*\s]+)\[(\d+)\](\w+)$/</span>
      <span class="ruby-identifier">mems</span>.<span class="ruby-identifier">push</span>(<span class="ruby-node">$3</span>)
      <span class="ruby-identifier">tys</span>.<span class="ruby-identifier">push</span>([<span class="ruby-identifier">parse_ctype</span>(<span class="ruby-node">$1</span>.<span class="ruby-identifier">strip</span>, <span class="ruby-identifier">tymap</span>), <span class="ruby-node">$2</span>.<span class="ruby-identifier">to_i</span>])
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span>(<span class="ruby-constant">RuntimeError</span>,<span class="ruby-node">&quot;can&#39;t parse the struct member: #{msig}&quot;</span>)
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">tys</span>, <span class="ruby-identifier">mems</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-compact" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">compact</span><span
                                class="method-args">(signature)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="compact-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle/cparser.rb, line 273</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">compact</span>(<span class="ruby-identifier">signature</span>)
  <span class="ruby-identifier">signature</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/\s+/</span>, <span class="ruby-string">&#39; &#39;</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/\s*([\(\)\[\]\*,;])\s*/</span>, <span class="ruby-string">&#39;\1&#39;</span>).<span class="ruby-identifier">strip</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-split_arguments" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">split_arguments</span><span
                                class="method-args">(arguments, sep=&#39;,&#39;)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="split_arguments-source">
            <pre><span class="ruby-comment"># File fiddle/lib/fiddle/cparser.rb, line 268</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">split_arguments</span>(<span class="ruby-identifier">arguments</span>, <span class="ruby-identifier">sep</span>=<span class="ruby-string">&#39;,&#39;</span>)
  <span class="ruby-keyword">return</span> [] <span class="ruby-keyword">if</span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">strip</span> <span class="ruby-operator">==</span> <span class="ruby-string">&#39;void&#39;</span>
  <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/([\w\*\s]+\(\*\w*\)\(.*?\)|[\w\*\s\[\]]+|\.\.\.)(?:#{sep}\s*|\z)/</span>).<span class="ruby-identifier">collect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span>[<span class="ruby-value">0</span>]}
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

